package com.example.microinvestuser.service.user.impl;
import com.example.microinvestcommon.pojo.Result;
import com.example.microinvestcommon.util.ThreadLocalUtil;
import com.example.microinvestuser.dao.UserUploadDao;
import com.example.microinvestuser.service.user.UserUploadService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Map;

@Service
public class UserUploadServiceImpl implements UserUploadService {

    private UserUploadDao userUploadDao;

    @Autowired
    public UserUploadServiceImpl(UserUploadDao userUploadDao){
        this.userUploadDao=userUploadDao;
    }

    //上传用户头像
    @Transactional
    @Override
    public Result<String> uploadUserProfile(String url) {
        // 通过当前线程的 Token 获取用户信息
        Map<String, String> map = ThreadLocalUtil.get();
        String userName = map.get("userName");

        try {
            userUploadDao.userUploadProfile(url,userName);
        }
        catch (Exception E){
            return Result.error(E.getMessage());
        }
        return Result.success(url);
    }
}
